﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.CApMovMovieManagerApp
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.Drawing;
using Tecnomatix.Engineering;
using Tecnomatix.Planning;


namespace DnProcessSimulateCommands;

public class CApMovMovieManagerApp
{
  private static ArrayList m_nodeOperationsList;
  private ITxObject m_operationRoot;
  private IList<TxPresentationModeSchema> m_presentationShemas;

  public bool PresentationModeState
  {
    get => TxApplication.Options.Simulation.PresentationMode;
    set => TxApplication.Options.Simulation.PresentationMode = value;
  }

  public string PresentationMode
  {
    get
    {
      string presentationMode = "";
      if (TxApplication.Options.Simulation.CurrentPresentationModeSchema != null)
        presentationMode = TxApplication.Options.Simulation.CurrentPresentationModeSchema.Name;
      return presentationMode;
    }
    set
    {
      foreach (TxPresentationModeSchema presentationShema in (IEnumerable<TxPresentationModeSchema>) this.m_presentationShemas)
      {
        if (presentationShema.Name == value)
        {
          TxApplication.Options.Simulation.CurrentPresentationModeSchema = presentationShema;
          break;
        }
      }
    }
  }

  public CApMovMovieRecorder Recorder { get; set; }

  public CApMovMovieManagerApp()
  {
    CApMovMovieManagerApp.m_nodeOperationsList = new ArrayList();
    this.m_presentationShemas = TxApplication.Options.Simulation.PresentationModeSchemas;
  }

  public ArrayList CreateOperationTreeNodes()
  {
    TxObjectList filteredItems = TxApplication.ActiveSelection.GetFilteredItems((ITxTypeFilter) new TxTypeFilter(typeof (ITxCompoundOperation)));
    if (((Collection<ITxObject>) filteredItems).Count == 0)
    {
      this.m_operationRoot = (ITxObject) TxApplication.ActiveDocument.OperationRoot;
      ((Collection<ITxObject>) filteredItems).Add(this.m_operationRoot);
    }
    else if (((Collection<ITxObject>) filteredItems).Count == 1)
      this.m_operationRoot = ((Collection<ITxObject>) filteredItems)[0];
    if (TxApplication.PlatformType == null)
      this.CollectAllOperationsFromTC(filteredItems, 0);
    else if (TxApplication.PlatformType == 1)
      this.CollectAllOperationsFromEMS(filteredItems, 0);
    return CApMovMovieManagerApp.m_nodeOperationsList;
  }

  private void CollectAllOperationsFromEMS(TxObjectList operationsList, int level)
  {
    TxTypeFilter txTypeFilter = new TxTypeFilter(new Type[1]
    {
      typeof (ITxCompoundOperation)
    }, new Type[1]{ typeof (ITxLocationOperation) });
    foreach (ITxObject operations in (Collection<ITxObject>) operationsList)
    {
      if (operations is TxObjectFlowOperation || operations is ITxCompoundOperation)
      {
        CApMovMovieManagerNodeData operationNode = CApMovMovieManagerApp.GetOperationNode(operations, level);
        CApMovMovieManagerApp.m_nodeOperationsList.Add((object) operationNode);
      }
      else if (!(operations.Collection is TxObjectFlowOperation) && !(operations is TxOperationRoot))
        break;
      if (operations is ITxCompoundOperation)
      {
        TxObjectList directDescendants = ((ITxObjectCollection) operations).GetDirectDescendants((ITxTypeFilter) txTypeFilter);
        if (((Collection<ITxObject>) directDescendants).Count > 0)
          this.CollectAllOperationsFromEMS(directDescendants, level + 1);
      }
      else if (operations is TxOperationRoot)
      {
        TxObjectList directDescendants = ((TxOperationRoot) operations).GetDirectDescendants((ITxTypeFilter) txTypeFilter);
        if (((Collection<ITxObject>) directDescendants).Count > 0)
          this.CollectAllOperationsFromEMS(directDescendants, level);
      }
    }
  }

  private void CollectAllOperationsFromTC(TxObjectList operationsList, int level)
  {
    TxTypeFilter txTypeFilter = new TxTypeFilter(typeof (ITxCompoundOperation));
    foreach (ITxObject operations in (Collection<ITxObject>) operationsList)
    {
      switch (operations)
      {
        case ITxTcOperation _:
        case TxTcActivity _:
        case TxTcProcess _:
          CApMovMovieManagerNodeData operationNode = CApMovMovieManagerApp.GetOperationNode(operations, level);
          CApMovMovieManagerApp.m_nodeOperationsList.Add((object) operationNode);
          if (operations is ITxCompoundOperation)
          {
            TxObjectList directDescendants = ((ITxObjectCollection) operations).GetDirectDescendants((ITxTypeFilter) txTypeFilter);
            if (((Collection<ITxObject>) directDescendants).Count > 0)
            {
              this.CollectAllOperationsFromTC(directDescendants, level + 1);
              continue;
            }
            continue;
          }
          continue;
        case TxOperationRoot _:
          TxObjectList directDescendants1 = ((TxOperationRoot) operations).GetDirectDescendants((ITxTypeFilter) txTypeFilter);
          if (((Collection<ITxObject>) directDescendants1).Count > 0)
          {
            this.CollectAllOperationsFromTC(directDescendants1, level);
            continue;
          }
          continue;
        default:
          continue;
      }
    }
  }

  private static CApMovMovieManagerNodeData GetOperationNode(ITxObject obj, int level)
  {
    ITxPlanningObject planningRepresentation = CApMovMovieManagerApp.GetObjectPlanningRepresentation(obj);
    Bitmap icon = planningRepresentation.PlatformServicesProvider.Icon as Bitmap;
    return new CApMovMovieManagerNodeData(level, icon, planningRepresentation);
  }

  private static ITxPlanningObject GetObjectPlanningRepresentation(ITxObject obj)
  {
    ITxProcessModelObject processModelObject = obj as ITxProcessModelObject;
    if (!(obj is ITxPlanningObject planningRepresentation) && processModelObject != null)
      planningRepresentation = processModelObject.PlanningRepresentation;
    return planningRepresentation;
  }

  public StringCollection GetPresentationModeShemes()
  {
    StringCollection presentationModeShemes = new StringCollection();
    foreach (TxPresentationModeSchema presentationShema in (IEnumerable<TxPresentationModeSchema>) this.m_presentationShemas)
      presentationModeShemes.Add(presentationShema.Name);
    return presentationModeShemes;
  }

  public enum AVIGenerationMode
  {
    AddAditionalMovies,
    CreateMissingMovies,
    OverrideAllMovies,
  }
}
